package cn.kgc.article.service;

import cn.kgc.article.mapper.ArticleMapper;
import cn.kgc.common.entity.Article;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by teacher ZHANG on 2022/11/14
 */
@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements ArticleService {
    @Override
    public Integer saveArticle(Article article) {
        //使用getBaseMapper()获取mapper
        return getBaseMapper().insertArticle(article);
    }

    @Override
    public Integer updateArticle(Article article) {
        return getBaseMapper().updateArticle(article);
    }

    @Override
    public List<Article> listByArticleIds(List<Integer> articleIds) {
        QueryWrapper<Article> wrapper = new QueryWrapper<>();
        wrapper.select("articleId", "title", "createDate");
        wrapper.in("articleId", articleIds);

        return getBaseMapper().selectList(wrapper);
    }
}
